// import '@babel/polyfill'
import Vue from 'vue';
import router from '@/router';
import '@/common/common.less';

import Skin from '@/component/skin';
Vue.component(Skin.name, Skin);

import AmountControl from '@/component/amount-control';
Vue.component(AmountControl.name, AmountControl);

import SelectControl from '@/component/select-control';
Vue.component(SelectControl.name, SelectControl);

import ControlSelect from '@/component/ControlSelect';
Vue.component(ControlSelect.name, ControlSelect);

import ControlAmount from '@/component/ControlAmount';
Vue.component(ControlAmount.name, ControlAmount);

import ControlPassword from '@/component/ControlPassword';
Vue.component(ControlPassword.name, ControlPassword);

import ControlDialog from '@/component/ControlDialog';
Vue.component(ControlDialog.name, ControlDialog);

import ControlLine from '@/component/ControlLine';
Vue.component(ControlLine.name, ControlLine);

import RateChart from '@/component/RateChart';
Vue.component(RateChart.name, RateChart);

import PlanIcon from '@/component/PlanIcon';
Vue.component(PlanIcon.name, PlanIcon);

import Vue2TouchEvents from 'vue2-touch-events';
Vue.use(Vue2TouchEvents);

import '@/db/dose';

import '@/db/advance';
import '@/db/rate';
import '@/db/excharge';
import '@/db/machine';
import '@/db/MenuSwitch';

import '@/plugin/rem/index.js';

import image from '@/assets/youbeng-bg.png';

import 'animate.css';

let v = new Vue({
	data: {
		loaded: false,
	},
	el: '#app',
	router,
	created() {
		const vm = this;
		const d = document.createElement('img');
		d.setAttribute('src', image);
		d.addEventListener('load', function() {
			vm.loaded = true;
		});

		var app = document.getElementsByClassName('app')[0];
		var touchstartY;
		app.addEventListener(
			'touchstart',
			function(event) {
				console.log(1);
				var events = event.touches[0] || event;
				touchstartY = events.clientY; //获取触摸目标在视口中的y坐标
			},
			false
		);

		app.addEventListener(
			'touchmove',
			function(event) {
				var events = event.touches[0] || event;
				//注意app.scrollTop始终为0
				var scrollTop = app.scrollTop || document.documentElement.scrollTop; //获取滚动部分的高度
				var clientHeight = document.documentElement.clientHeight; //获取手机屏幕高度（可视部分高度）
				var scrollHeight = app.scrollHeight; //所有内容的高度
				if (events.clientY > touchstartY && scrollTop === 0 && event.cancelable) {
					event.preventDefault(); //禁止到顶下拉
				} else if (scrollTop + clientHeight > scrollHeight && event.cancelable) {
					// event.preventDefault(); //禁止到底上拉
				}
			},
			false
		);
	},
});
